package com.douziit.meilianoa.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.douziit.meilianoa.base.request.PageRequest;
import com.douziit.meilianoa.base.response.ResponseData;
import com.douziit.meilianoa.base.response.ResponseUtil;
import com.douziit.meilianoa.entity.ProjectEvalution;
import com.douziit.meilianoa.entity.ProjectInfo;
import com.douziit.meilianoa.service.ProjectEvalutionService;
import com.douziit.meilianoa.service.ProjectInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * 项目评价控制类
 */

@RestController
@RequestMapping("/projectEvalution")
public class ProjectEvalutionController {


    @Autowired
    private ProjectEvalutionService projectEvalutionService;

    @Autowired
    private ProjectInfoService projectInfoService;

    /**
     * 添加评价
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/addPorojectEvalution/{projectId}")
    public ResponseData addProjectEvalution(@PathVariable("projectId") Integer projectId, @RequestBody ProjectEvalution projectEvalution){
        projectEvalutionService.save(projectEvalution);
        ProjectInfo projectInfo = new ProjectInfo();
        projectInfo.setId(projectId);
        projectInfo.setProjectEvalutionId(projectEvalution.getId());
        return ResponseUtil.jsonSuccess(0);
    }


    /**
     * 修改评价
     */
    @PostMapping("/changePorojectEvalution")
    public ResponseData changeProjectEvalution(@RequestBody ProjectEvalution projectEvalution){
        projectEvalutionService.updateById(projectEvalution);
        return ResponseUtil.jsonSuccess(0);
    }

    /**
     * 项目评价详情
     */
    @PostMapping("/PorjectEvalutionDetail")
    public ResponseData PorjectEvalutionDetail(@RequestBody PageRequest req){

        ProjectInfo projectInfo = projectInfoService.getById(req.getProjectId());
        ProjectEvalution projectEvalution = projectEvalutionService.getOne(new QueryWrapper<ProjectEvalution>().eq("id",projectInfo.getProjectEvalutionId()));
        return ResponseUtil.jsonSuccess(projectEvalution);
    }
}
